package com.songlanyun.modules.interact.impl;

import com.songlanyun.common.utils.RedisKeys;
import com.songlanyun.modules.interact.IInteractService;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service("iInteractService")
public class InteractManageServiceImpl implements IInteractService {

    private Map<String, IInteractService> iServices = new HashMap<>();

    public InteractManageServiceImpl(IInteractService opusInteractService, IInteractService articleInteractService) {
        iServices.put(RedisKeys.BbsKey.BROWSE_OPUS_KEY.getKey(), opusInteractService);
        iServices.put(RedisKeys.BbsKey.LIKE_OPUS_KEY.getKey(), opusInteractService);
        iServices.put(RedisKeys.BbsKey.SHARE_OPUS_KEY.getKey(), opusInteractService);

        iServices.put(RedisKeys.BbsKey.BROWSE_ARTICLE_KEY.getKey(), articleInteractService);
        iServices.put(RedisKeys.BbsKey.LIKE_ARTICLE_KEY.getKey(), articleInteractService);
        iServices.put(RedisKeys.BbsKey.SHARE_ARTICLE_KEY.getKey(), articleInteractService);

    }

    @Override
    public void browseSave(BoundHashOperations<String, String, Object> result) {
        String key = result.getKey();

        if (iServices.containsKey(key)) {
            iServices.get(key).browseSave(result);
        }

//        if (key.equals(RedisKeys.BbsKey.BROWSE_OPUS_KEY.getKey())) {
//            opusService.browseSave(result);
//        }
//
//        if (key.equals(RedisKeys.BbsKey.BROWSE_ARTICLE_KEY.getKey())) {
//            articleService.browseSave(result);
//        }
    }

    @Override
    public void likeSave(BoundHashOperations<String, String, Object> result) {

        String key = result.getKey();

        if (iServices.containsKey(key)) {
            iServices.get(key).likeSave(result);
        }


//
//        if (key.equals(RedisKeys.BbsKey.LIKE_OPUS_KEY.getKey())) {
//            opusService.likeSave(result);
//        }
//
//        if (key.equals(RedisKeys.BbsKey.LIKE_ARTICLE_KEY.getKey())) {
//            articleService.likeSave(result);
//        }

    }

    @Override
    public void shareSave(BoundHashOperations<String, String, Object> result) {

        String key = result.getKey();
        if (iServices.containsKey(key)) {
            iServices.get(key).shareSave(result);
        }

//        if (key.equals(RedisKeys.BbsKey.SHARE_OPUS_KEY.getKey())) {
//            opusService.shareSave(result);
//        }
//
//        if (key.equals(RedisKeys.BbsKey.SHARE_ARTICLE_KEY.getKey())) {
//            articleService.shareSave(result);
//        }
    }


}
